package com.example.myapplication.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.myapplication.R;

public class BlankFragment1 extends Fragment {

    private  View root;
    private TextView textView;
    private IFragmentCallback fragmentCallback;


    public void setFragmentCallback(IFragmentCallback callback){
        Log.e("TAG", "onCreate:--------callbac0k:"+callback );
        fragmentCallback = callback;
        Log.e("TAG", "onCreate:--------callback1:"+callback );
        Log.e("TAG", "onCreate:--------callback2:"+fragmentCallback );
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = this.getArguments();
        if(bundle!=null){
            String mes = bundle.getString("message");
            Log.e("TAG", "onCreate:"+mes );
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        if(root==null){
            root = inflater.inflate(R.layout.fragment_blank1,container,false);
        }
        ///callBack回调
        Button callbackBtn = root.findViewById(R.id.callback_btn1);
        Log.e("TAG", "onCreate:--------callback4:"+fragmentCallback );
        Log.e("TAG", "onCreate:--------callbackBtn5:"+callbackBtn );
        callbackBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("TAG", "onClick: ----------0" );
                Log.e("TAG", "onClick: ----------"+fragmentCallback );
                if(fragmentCallback!=null){
                    fragmentCallback.sendMsgToActivity("我反手回调出一份信");
                }
                Log.e("TAG", "onClick: ----------1" );
            }
        });

        ///一个fragment，已经fragment的简单业务
        textView = root.findViewById(R.id.blank_textView);
        Button btn = root.findViewById(R.id.blank_btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                textView.setText("好的很。");
            }
        });
        return root;
    }

    @Override
    public void onResume() {
        super.onResume();

    }
}